<template>
  <div class="locationView fff">
    <div class="left">
      <div class="title">库区选择</div>
      <div class="selector">
        <el-form>
          <el-form-item>
            <el-select v-model="isOption" placeholder="请选择">
              <el-option
                v-for="(item, index) in warehouseType"
                :key="index"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div class="areaContent">
        <div class="condition">
          <el-form>
            <el-form-item>
              <el-input
                v-model="areaName"
                suffix-icon="el-icon-search"
                placeholder="请输入库区名称"
              />
            </el-form-item>
          </el-form>
        </div>
        <div class="details">
          <div v-if="areaList.length" class="list">
            <el-scrollbar>
              <div
                v-for="item in areaList"
                :key="item.id"
                :class="{ item: true, isActive: location === item.id }"
                @click="setLocation(item.id)"
              >
                {{ item.name }}
              </div>
            </el-scrollbar>
          </div>
          <div v-else class="now">
            <div class="tip">暂无库区</div>
            <el-button type="success" @click="$router.push('/manage-base-info/area/details/null')">新增库区</el-button>
          </div>
        </div>
      </div>
    </div>
    <div class="divsion" />
    <div class="right">
      <div class="top">
        <div class="divTitle">库区总览</div>
        <div class="overView">
          <div class="item">库存总计: &emsp;{{ overView.total }}</div>
          <div class="item">
            <div class="square" style="background: rgb(195, 195, 195)" />
            <div class="label">停用库位: &emsp;{{ overView.stop }}</div>
          </div>
          <div class="item">
            <div class="square" style="background: rgb(0, 190, 118)" />
            <div class="label">占用库位: &emsp;{{ overView.use }}</div>
          </div>
          <div class="item">
            <div class="square" style="background: rgb(178, 220, 204)" />
            <div class="label">空闲库位: &emsp;{{ overView.free }}</div>
          </div>
        </div>
      </div>
      <div v-if="allLocation.length" class="content">
        <div
          v-for="item in allLocation"
          :key="item.id"
          :class="{
            itemCount: true,
            use: +item.status && +item.useStatus,
            free: +item.status && !+item.useStatus,
          }"
        />
      </div>
      <div v-else class="now">
        <div class="box">
          <div class="img" />
          <div class="tip">暂无库位</div>
          <el-button type="success" @click="$router.push('/manage-base-info/location/details/null')">新增库位</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getAllWarehouseList } from '@/api/wareHouse'
import { getAllAreaList, areaOverview } from '@/api/area'
import { getAllLocationDetailsList } from '@/api/location'
export default {
  data() {
    return {
      warehouseType: [],
      isOption: null,
      queryArea: {},
      areaName: null,
      areaList: [],
      location: null,
      overView: {
        total: 0,
        stop: 0,
        use: 0,
        free: 0
      },
      allLocation: []
    }
  },
  watch: {
    async isOption() {
      this.queryArea = { status: 1, warehouseId: this.isOption }
      await this.getAllAreaList()
      this.areaOverview()
      this.getAllLocationDetailsList()
    },
    areaName(val) {
      this.queryArea.like_name = val
      this.getAllAreaList()
    }
  },
  created() {
    this.getAllWarehouseList()
  },
  methods: {
    setLocation(id) {
      this.location = id
      this.areaOverview()
      this.getAllLocationDetailsList()
    },
    async getAllWarehouseList() {
      const { data } = await getAllWarehouseList({ status: 1 })
      this.warehouseType = data
      this.isOption = data[0]?.id
    },
    async getAllAreaList() {
      const res = await getAllAreaList(this.queryArea)
      this.areaList = res.data
      this.location = this.areaList[0]?.id
    },
    async areaOverview() {
      if (!this.location) {
        this.overView = {
          total: 0,
          stop: 0,
          use: 0,
          free: 0
        }
        return
      }
      const { data } = await areaOverview(this.location)
      this.overView = data
    },
    async getAllLocationDetailsList() {
      if (!this.location) {
        this.allLocation = []
        return
      }
      const { data } = await getAllLocationDetailsList({
        areaId: this.location
      })
      this.allLocation = data
    }
  }
}
</script>

<style lang="scss" scoped>
div.locationView {
  display: flex;
  width: 100%;
  min-height: 500px;
  height: calc(100vh - 114px);
  padding: 0;
  .left {
    width: 263px;
    padding: 27px 20px;
    .title {
      width: 64px;
      height: 22px;
      font-size: 16px;
      font-family: PingFangSC, PingFangSC-Medium;
      font-weight: 500;
      text-align: left;
      color: #332929;
      line-height: 22px;
      margin-bottom: 22px;
      margin-left: 10px;
    }
    .selector {
      .el-form-item {
        width: 100%;
      }
    }
    .areaContent {
      width: 224px;
      background: #fdfcf9;
      border: 1px solid #f7f2f1;
      border-radius: 6px;
      padding: 30px 29px 0 26px;
      .el-form-item {
        width: 100%;
      }
    }
    .details {
      height: calc(100vh - 360px);
      position: relative;
      .list {
        height: 100%;
        .el-scrollbar {
          height: 100%;
          ::v-deep .el-scrollbar__wrap {
            overflow-x: hidden !important;
          }
          .el-scrollbar__view {
            height: calc(100% - 500px);
          }
          .item {
            width: 140px;
            height: 40px;
            background: #fff;
            border-radius: 4px;
            box-shadow: 0 0 6px 0 rgb(255 178 0 / 40%);
            margin: 0 auto;
            margin-top: 20px;
            font-size: 13px;
            font-weight: 500;
            text-align: center;
            color: #ffb200;
            line-height: 40px;
            cursor: pointer;
            &.isActive {
              background: #ffb200;
              color: #332929;
            }
          }
        }
      }
      .now{
        height: 100%;
        display: flex;
        justify-content: center;
        flex-direction: column;
        text-align: center;
        .tip{
          margin-bottom: 20px;
          color:#b5abab;
          font-weight: 700;
        }
      }
    }
  }
  .divsion {
    width: 10px;
    height: 100%;
    background: linear-gradient(
      270deg,
      hsla(0, 0%, 100%, 0),
      rgba(99, 97, 96, 0.1)
    );
  }
  .right {
    flex: 1;
    padding: 27px 20px;
    .top {
      margin-bottom: 21px;
      height: 22px;
      .divTitle {
        width: 64px;
        height: 22px;
        font-size: 16px;
        font-family: PingFangSC, PingFangSC-Medium;
        font-weight: 500;
        text-align: left;
        color: #332929;
        line-height: 22px;
        float: left;
        margin-right: 103px;
      }
      .overView {
        float: left;
        .item {
          float: left;
          width: 100px;
          margin-right: 43px;
          height: 22px;
          line-height: 22px;
          font-weight: 400;
          text-align: left;
          color: #424250;
          .square {
            float: left;
            width: 12px;
            height: 12px;
            border-radius: 3px;
            margin-top: 5px;
            margin-right: 7px;
          }
        }
      }
    }
    .itemCount {
      display: inline-block;
      background-color: rgb(195, 195, 195);
      width: 36px;
      height: 36px;
      border-radius: 7px;
      margin: 5px;
      &.use {
        background-color: #00be76 !important;
      }
      &.free {
        background-color: #b2dccc !important;
      }
    }
    .now {
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      text-align: center;
      .img {
        width: 160px;
        height: 160px;
        display: inline-block;
        background: url(http://www-wms-java.itheima.net/img/empty.4300e933.png)
          no-repeat;
        background-size: contain;
      }
      .tip{
        margin: 10px;
        color: #b5abab;
      }
    }
  }
}
</style>
